package jdk8;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;

public class FunctionTest {
    public static void main(String[] args) {
        Function<Integer, Integer> test = i -> i + 1;
        System.out.println(test.apply(5));
        MyFunction myFunction = new MyFunction();
        MyBiFunction biFunction = new MyBiFunction();
        String hello = "hello";
        String name = "zhang";

        int num = myFunction.apply(hello);
        String valueBi = biFunction.apply(hello, name);
        //hello长度返回
        System.out.println(num);
        System.out.println(valueBi);

        new Thread(() -> System.out.println(" thread start ")).start();
        Function<String, String> test1 = (e) -> {
            System.out.println(" thread start ");
            return e;
        };

        System.out.println(test1.apply("thread2"));
        List<String> list = Lists.newArrayList();
        list.add("zhang");
        list.add("li");
        list.forEach(MyFunction2::print);

        System.out.println(MyFunction3.isYes(s -> s.equals("yes"), "no"));
        Predicate<String> predicate = s -> s.equals("yes");
        System.out.println(MyFunction3.isYes(predicate, "yes"));

    }
}

class MyFunction implements Function<String, Integer> {

    @Override
    public Integer apply(String s) {
        return s.length();
    }
}

class MyBiFunction implements BiFunction<String, String, String> {
    @Override
    public String apply(String s, String s2) {
        return s + ";" + s2;
    }
}

class MyFunction2 {
    public static String print(String s) {
        System.out.println(s);
        return s;
    }
}

class MyFunction3 {
    public static String isYes(Predicate<String> predicate, String string) {
        return String.valueOf(predicate.test(string));
    }
}




